main()
{
	long a[6]={2,3,5,9,8,6},s[10],n;
	for(gets(&n);~scanf("%ld",&n);)
	{
		s[0]=1;
		s[1]=a[n%6];
		s[2]=a[(n+1)%6];
		s[3]=n%2?7:4;
		s[4]=a[(n+2)%6];
		s[5]=a[(n+5)%6];
		s[6]=n%2?4:7;
		s[7]=a[(n+4)%6];
		s[8]=a[(n+3)%6];
		s[9]=10;

		for(n=0;n<10;printf(n==10?"%ld\n":"%ld ",s[n++]));
	}
}
